package com.kuang.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @author luomingliang
 * @date 2021/5/13 20:57
 * 8锁，就是关于锁的8个问题
 *      1.标准情况下，两个线程先输出发短信还是打电话？ //发短信
 *      2.sendSms延迟4秒。哪个先输出？ //发短信
 */
public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();

        new Thread(()->{
            phone.sendSms();
        } , "A").start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(()->{
            phone.call();
        } , "B").start();
    }
}


class Phone {

    public synchronized void sendSms() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    public synchronized void call() {
        System.out.println("打电话");
    }
}